<?php
/**
 *
 *
 */
class Yz_Form_Element_OneToMany
    extends Yz_Form_Element_Abstract
{


    /****************************
     *      Public methods      *
     ****************************/

    /**
     *
     *
     */
    public function render(Yz_Template_Interface $template)
    {
        $relHref = $template->YzModuleHref;
        $o = "";
        if ($this->value) {
            $list = new Yz_Hash($this->value);
            $list->apply(function($i, $v) use (&$o, $relHref) {
                $title = $v->getTitle();
                $o .= <<<html
                    <div class="dclub-catalog-article">
                        <a href="{$relHref}delete-article/{$i}"
                            title="Удалить #{$i}"
                            onclick="Dclub.Admin.Catalog.deleteArticle(this);return false"
                            >Удалить</a>
                        <a href="{$relHref}edit-article/{$i}"
                            title="Редактировать комплект #{$i}"
                            onclick="Dclub.Admin.Catalog.editArticle(this);return false"
                            >Редактировать</a>
                        <strong>{$title}</strong>
                    </div>\n
html;
            });
        }
        $itemId = $this->form->getValues()->id;
        $o .= <<<html
            <a href="{$relHref}add-article/{$itemId}"
                title="Добавить комплект к товару #{$itemId}"
                onclick="Dclub.Admin.Catalog.addArticle(this); return false"
                >Добавить комплект</a>
html;
        false and $template
            ->includeCSS('./www/Dclub/styles/admin.css')
            ->includeJS('./www/Dclub/js/Dclub.Admin.js')
        ;
        return $o;
    }


    public function isParseable()
    {
        return false;
    }

}
